package com.zjj.distributed.zk.curator.watcher;

import com.zjj.distributed.zk.curator.CuratorBaseOperations;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.api.CuratorEvent;
import org.junit.Test;

/**
 * @author zhanglei.zjj
 * @description TODO
 * @date 2023/6/20 20:53
 */
@Slf4j
public class CuratorListenerTest extends CuratorBaseOperations {
    @Test
    public void testCuratorListener() throws Exception {
        curatorFramework.getCuratorListenable().addListener((CuratorFramework client, CuratorEvent event) -> {
            log.info(" things changed1: event: {},  {} ", event.getType().name(), event);
        });

        String path = "/test";
        createIfNeed(path, "test");
        log.info("start to change data for path :{}", path);
        curatorFramework.setData().inBackground().forPath(path, "xxx1".getBytes());
        log.info("start to change data for path :{} again", path);
        curatorFramework.setData().inBackground().forPath(path, "xxx2".getBytes());

        Thread.sleep(Integer.MAX_VALUE);
    }
}
